package org.jmh.base.service.impl;

import org.jmh.base.mapper.BaseMapper;
import org.jmh.base.query.BaseQuery;
import org.jmh.base.service.IBaseService;
import org.jmh.base.util.PageInfo;
import org.jmh.org.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
// 要不要再这里 打@Service 和 @Transactional
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    BaseMapper<T> mapper;

    @Transactional
    @Override
    public void insert(T t) {

        mapper.insert(t);
    }

    @Transactional
    @Override
    public void update(T t) {

        mapper.update(t);
    }

    @Transactional
    @Override
    public void delete(Serializable id) {
        mapper.delete(id);
    }

    @Override
    public T selectById(Serializable id) {
        return mapper.selectById(id);
    }

    @Override
    public List<T> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public PageInfo queryPage(BaseQuery baseQuery) {
        // 查总数
        Long total = mapper.queryTotal(baseQuery);
        if (total > 0){
            // 查数据
            List<T> list = mapper.queryList(baseQuery);
            return new PageInfo<T>(total,list);
        }
        return new PageInfo<T>();
    }



    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);
    }
}
